package com.sjl.db137.controller;

import com.sjl.db137.config.R;
import com.sjl.db137.entity.Role;
import com.sjl.db137.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version 1.0
 * @Author sjl
 * @date 2024/12/31 10:23
 * @Description
 */
@RestController
@CrossOrigin(origins = "*")
public class RoleController {
    @Autowired
    private RoleService roleService;

    /***
     * 获取所有的角色集合
     * @return
     */
    @GetMapping("selectRole")
    public R selectRole() {
        List<Role> roleList = this.roleService.list();

        return new R().add("roleList", roleList);
    }

    /***
     * 根据用户id获取拥有的角色集合
     * @param userid 用户id
     * @return
     */
    @GetMapping("selectRoleByUserId/{userid}")
    public R selectRoleByUserId(@PathVariable("userid") int userid) {
        List<Role> roleList = this.roleService.selectRoleByUserId(userid);
        return new R().add("roleList", roleList);
    }



}
